﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicService
{
    public partial class MusicService:ISongGenreService
    {
        public bool addSongGenre(string genreID, string songID)
        {
            bool flag = false;
            SongGenre songGenre = new SongGenre();
            try
            {
                songGenre.GenreID = genreID;
                songGenre.SongID = songID;
                dc.SongGenres.InsertOnSubmit(songGenre);
                dc.SubmitChanges();
                flag = true;
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool removeSongGenre(string genreID, string songID)
        {
            bool flag = false;
            try
            {
                SongGenre songGenre = dc.SongGenres.Single(tmp => tmp.GenreID.Equals(genreID) &&
                    tmp.SongID.Equals(songID));
                if (songGenre != null)
                {
                    dc.SongGenres.DeleteOnSubmit(songGenre);
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }

        public bool updateSongGenre(string genreID, string songID)
        {
            bool flag = false;
            try
            {
                SongGenre songGenre = dc.SongGenres.Single(tmp => tmp.GenreID.Equals(genreID) &&
                    tmp.SongID.Equals(songID));
                if (songGenre != null)
                {
                    songGenre.GenreID = genreID;
                    songGenre.SongID = songID;
                    dc.SubmitChanges();
                    flag = true;
                }
            }
            catch (Exception)
            {

            }
            return flag;
        }
        public List<SongGenre> getAllSongGenre()
        {
            var list = from sg in dc.SongGenres select sg;
            return list.ToList();
        }
        public SongGenre getSongGenreByID(string genreID, string songID)
        {
            SongGenre songGenre = dc.SongGenres.Single(tmp => tmp.GenreID.Equals(genreID) &&
                tmp.SongID.Equals(songID));
            return songGenre;
        }
    }
}